package com.ruoyi.etravel.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.etravel.pojo.dto.ScenicSpotDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.etravel.pojo.entity.ScenicSpot;
import com.ruoyi.etravel.service.IScenicSpotService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景点信息Controller
 *
 * @author caochong
 * @date 2022-11-11
 */
@RestController
@RequestMapping("/etravel/spot")
public class ScenicSpotController extends BaseController
{
    @Autowired
    private IScenicSpotService scenicSpotService;


    /**
     * 根据景点id查询出对应的景点信息以及对应的评论内容
     * @param scenicId
     * @return
     */
    @GetMapping("/scenic/{scenicId}")
    public AjaxResult findScenicComment(@PathVariable Integer scenicId){
        return AjaxResult.success("查询成功",scenicSpotService.findScenicCommentById(scenicId));
    }

    /**
     * 根据经典相应的等级，名称，或者所在区查询符合条件的景点
     * @param pageNum
     * @param pageSize
     * @param scenicSpotDto
     * @return
     */
    @PostMapping("/pageScenicList/{pageNum}/{pageSize}")
    public AjaxResult pageScenicList(@PathVariable("pageNum") int pageNum,
                                     @PathVariable("pageSize") int pageSize,
                                     @RequestBody ScenicSpotDto scenicSpotDto){
        return scenicSpotService.pageScenicList(pageNum,pageSize,scenicSpotDto);

    }

    /**
     * 查询景点信息列表
     */
    @PreAuthorize("@ss.hasPermi('etravel:spot:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScenicSpot scenicSpot)
    {
        startPage();
        List<ScenicSpot> list = scenicSpotService.selectScenicSpotList(scenicSpot);
        return getDataTable(list);
    }

    /**
     * 导出景点信息列表
     */
    @PreAuthorize("@ss.hasPermi('etravel:spot:export')")
    @Log(title = "景点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScenicSpot scenicSpot)
    {
        List<ScenicSpot> list = scenicSpotService.selectScenicSpotList(scenicSpot);
        ExcelUtil<ScenicSpot> util = new ExcelUtil<ScenicSpot>(ScenicSpot.class);
        util.exportExcel(response, list, "景点信息数据");
    }

    /**
     * 获取景点信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('etravel:spot:query')")
    @GetMapping(value = "/{scenicId}")
    public AjaxResult getInfo(@PathVariable("scenicId") Long scenicId)
    {
        return AjaxResult.success(scenicSpotService.selectScenicSpotByScenicId(scenicId));
    }

    /**
     * 新增景点信息
     */
    @PreAuthorize("@ss.hasPermi('etravel:spot:add')")
    @Log(title = "景点信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScenicSpot scenicSpot)
    {
        return toAjax(scenicSpotService.insertScenicSpot(scenicSpot));
    }

    /**
     * 修改景点信息
     */
    @PreAuthorize("@ss.hasPermi('etravel:spot:edit')")
    @Log(title = "景点信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScenicSpot scenicSpot)
    {
        return toAjax(scenicSpotService.updateScenicSpot(scenicSpot));
    }

    /**
     * 删除景点信息
     */
    @PreAuthorize("@ss.hasPermi('etravel:spot:remove')")
    @Log(title = "景点信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scenicIds}")
    public AjaxResult remove(@PathVariable Long[] scenicIds)
    {
        return toAjax(scenicSpotService.deleteScenicSpotByScenicIds(scenicIds));
    }
}
